package com.gcd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gcd.mapper.RegisterMapper;
import com.gcd.model.Member;
import com.gcd.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegisterServiceImpl implements RegisterService {
    private RegisterMapper registerMapper;

    @Autowired
    public void setRegisterMapper(RegisterMapper registerMapper) {
        this.registerMapper = registerMapper;
    }

    @Override
    public boolean register(Member member) {
        List<String> phone = registerMapper.searchPhone();
        for (String s : phone) {
            if (s.equals(member.getPhone())) {
                return false;
            }
        }
        return registerMapper.insert(member)==1;
    }

    @Override
    public boolean isPhoneExists(String phone) {
        return registerMapper.selectCount(new LambdaQueryWrapper<Member>().eq(Member::getPhone, phone)) > 0;
    }
}
